<?
$l_Product = $_lang == 'vn' ? 'Sản phẩm' : 'Product';
$l_Price = $_lang == 'vn' ? 'Giá' : 'Price';

$l_Keyword = $_lang == 'vn' ? 'Từ khóa' : 'Keyword';
$l_CheckboxLabel = $_lang == 'vn' ? 'Chỉ tìm trong phần mô tả sản phẩm' :
    'Only search in product detail';
$l_BelongTo = $_lang == 'vn' ? 'Trong danh mục' : 'Belong to';
$l_PriceFrom = $_lang == 'vn' ? 'Giá từ' : 'Price from';
$l_PriceTo = $_lang == 'vn' ? 'Giá đến' : 'Price to';
$l_DateFrom = $_lang == 'vn' ? 'Từ ngày' : 'From date';
$l_DateTo = $_lang == 'vn' ? 'Đến ngày' : 'To date';

$l_DateFormat = $_lang == 'vn' ? 'Tháng / ngày / năm' : 'month / day / year';
?>
<?
$per_page = 6;
$p = 0;
if ($_REQUEST['p'] != '')
    $p = killInjection($_REQUEST['p']);

if (isset($_REQUEST['act'])) {
?>
<?
    $where = "1=1";
    $keyword = killInjection($_REQUEST['keyword']);
    if ($keyword != '') {
        $where .= " and (detail_short like '%" . $keyword . "%'";
        if (!isset($_REQUEST['search_in_detail']))
            $where .= "or name like '%" . $keyword . "%'";
        $where .= ") ";
    }
    if ($_REQUEST['parent'] != '')
        $where .= " and parent=" . $_REQUEST['parent'];
    if ($_REQUEST['pfrom'] != '')
        $where .= " and price>=" . $_REQUEST['pfrom'];
    if ($_REQUEST['pto'] != '')
        $where .= " and price<=" . $_REQUEST['pto'];
    if ($_REQUEST['dfrom'] != '')
        $where .= " and date_added>=" . $_REQUEST['dfrom'];
    if ($_REQUEST['dto'] != '')
        $where .= " and date_added<=" . $_REQUEST['dto'];

    $p = 0;
    if ($_REQUEST['p'] != '')
        $p = $_REQUEST['p'];

    $result = mysql_query("select count(*) from tbl_product where $where", $conn);
    $total = mysql_fetch_row($result);
    $sql = "select * from tbl_product where $where limit " . $per_page * $p . "," .
        $per_page;
    $result = mysql_query($sql, $conn);
    $total = $total[0];
    if ($total == 0) { ?>
<?php include_once("module/include/analyticstracking.php") ?>
<table align="center" width="98%" border="0" cellSpacing="0" cellPadding="0">
  <tr>
    <td colspan="3" height="800" align="center" valign="top"><font color="#B11400"><b>Không tìm thấy sản phẩm</b></font></td>
  </tr>
</table>
<?
    } else {  ?>
<div class="title_left_bg"></div>
<div class="title_center_bg">
  <div class="title_center_icon"></div>
  Kết quả tìm kiếm </div>
<div class="title_right_bg"></div>
<table width="100%" border="0">
  <tr>
    <td width="16%">&nbsp;</td>
    <td width="63%"><h2><?= $l_Product ?></h2></td>
    <td width="21%" align="center"><h2><?= $l_Price ?></h2></td>
  </tr>
  <?
        while ($row = mysql_fetch_assoc($result)) {
            $strLinkFriendly = unicodeToNonUnicode($row['name']);
  ?>
  <tr>
    <td><a title="khohangtot| do gia dung" href="/khohangtot/product-detail/<?= $row['id'] ?>/<?=$strLinkFriendly?>.htm"> <img title="<?= $row['name'] ?>" width="110" height="100px" src="/khohangtot/images/product/images/<?= $row['image'] ?>" border="0"> </a></td>
    <td><a title="khohangtot| do gia dung" href="/khohangtot/product-detail/<?= $row['id'] ?>/<?=$strLinkFriendly?>.htm" class="style3"> <b>
      <?= $row['name'] ?>
      </b> </a> <br />
      <?=strip_tags($row['detail_short'])?></td>
    <td align="center"><strong>
      <?= $row['price'] == 0 ? '<a title="'.$row['name'].'">Call</a>' : number_format($row['price'],0, ',', '.') ?>
      &nbsp;&nbsp;
      <?=$currencyUnit ?>
      </strong>
      </td>
  </tr>
  <tr><td colspan="3" style="border: 1px solid #eee;"></td></tr>
  <?
    }
	?>
</table>
<div class="page-bottom">
Trang : <span>
<?
        $newsPage = $_lang == "vn" ? "Sản phẩm" : "Products";
        $pagePage = $_lang == "vn" ? "Trang" : "Page";
        $titleFirst = $_lang == "vn" ? "Đầu" : "First";
        $titlePrevious = $_lang == "vn" ? "Trước" : "Previous";
        $titleNext = $_lang == "vn" ? "Tiếp" : "Next";
        $titleLast = $_lang == "vn" ? "Cuối" : "Last";

        $pages = countPages($total, $per_page);

        if ($p > 1)
            echo '<a title="khohangtot| do gia dung" href="/khohangtot/result-search'.
                 '/0' . '/'.$keyword.'/search.htm' .'">'.$titleFirst.'[&lt;&lt;]</a> ';
        if ($p > 0)
            echo '<a title="khohangtot| do gia dung"  href="/khohangtot/result-search' .
                '/' . ($p - 1) . '/'.$keyword.'/search.htm' .'">'.$titlePrevious.'[&lt;]</a> ';
        $from = ($p - 10 > 0 ? $p - 10 : 0);
        $to = ($p + 10 < $pages ? $p + 10 : $pages);
        for ($i = $from; $i < $to; $i++) {
            if ($i != $p)
                echo '<a title="khohangtot| do gia dung" href="/khohangtot/result-search'.
                '/' . $i . '/'.$keyword.'/search.htm' .'">' . ($i + 1) . ' </a>';
            else
                echo '<a title="khohangtot| do gia dung" class="select-a">' . ($i + 1) . '</a> ';
        }
        if ($p < $i - 1)
            echo '<a title="khohangtot| do gia dung" href="/khohangtot/result-search'.
                '/' . ($p + 1) .'/'.$keyword.'/search.htm'.'">'.$titleNext.'[&gt;]</a> ';
        if ($p < $pages - 1)
            echo '<a title="khohangtot| do gia dung" href="/khohangtot/result-search'.
                '/' . ($pages - 1). '/'.$keyword.'/search.htm'.
                '">'.$titleLast.'[&gt;&gt;]</a>';
?>
</span>
</div>
<div class="clear"></div>
<!--end .clear-->
<?
    }
}

$_SESSION['cats'] = $keyword; ?>
